#pragma once

 
namespace micro{
namespace utils
{

template<class T> 
class QStack
{

protected:

	class Node
	{
	public:

		T info;
		Node * next;
		Node(T t, Node * next = nullptr):info(t), next(next){}

	} * m_pTop;

 
public:

	QStack(){  m_pTop = nullptr; }
	~QStack()
	{
		EmptyStack();		
	}

	bool IsEmpty(){ return nullptr==m_pTop;}
	void EmptyStack()
	{
		while(m_pTop)
		{
			Node * p = m_pTop;
			m_pTop = m_pTop->next;
			delete p;
		}
	}
	
	T Pop() 
	{ 
		if (!IsEmpty() )
		{
			T t = m_pTop->info;
			Node * p = m_pTop;
			m_pTop = m_pTop->next;
			delete p;
			return t;
		}
		return T(0);
	}

	void Push(T & t)
	{
		Node * p = new Node(t, m_pTop);
		m_pTop = p;
	}
};

//typedef QStack<int> IntStack;

}//utils
}//micro